package com.open.thinks.todo.system.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.validator.constraints.NotBlank;

import com.open.thinks.todo.system.common.EnumContentHolder;
import com.open.thinks.todo.system.domain.helper.TaskPriority;
import com.open.thinks.todo.system.domain.helper.TaskRemider;
import com.open.thinks.todo.system.domain.helper.TaskStatus;
import com.open.thinks.todo.system.domain.helper.TaskType;

@Entity
@Table(name = "tasks")
public class Task {
	@Id
	@Column
	private String task_id;
	@Column
	@NotBlank(message = "subject can not be null")
	private String subject;
	@Column
	private TaskType type;
	@Column
	private String description;
	@ManyToOne
	@JoinColumn(name = "createby")
	private User createby;
	@ManyToOne
	@JoinColumn(name = "updateby")
	private User updateby;
	@Column
	private String create_date;
	@Column
	private String update_date;
	@Column
	@Enumerated(value = EnumType.ORDINAL)
	private TaskStatus status;
	@ManyToOne
	@JoinColumn(name = "assignee")
	private User assignee;
	@Column
	private String start_date;
	@Column
	private String due_date;
	@Column
	@Enumerated(value = EnumType.ORDINAL)
	private TaskPriority priority;
	@Column
	private String complete_progress;
	@Column
	@Enumerated(value = EnumType.ORDINAL)
	private TaskRemider reminder;

	public String getTask_id() {
		return task_id;
	}

	public void setTask_id(String task_id) {
		this.task_id = task_id;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public TaskType getType() {
		return type;
	}

	public void setType(TaskType type) {
		this.type = type;
	}

	public void setType(String type) {
		this.type = EnumContentHolder.valueOf(type, TaskType.class);
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getCreate_date() {
		return create_date;
	}

	public void setCreate_date(String create_date) {
		this.create_date = create_date;
	}

	public String getUpdate_date() {
		return update_date;
	}

	public void setUpdate_date(String update_date) {
		this.update_date = update_date;
	}

	public TaskStatus getStatus() {
		return status;
	}

	public void setStatus(TaskStatus status) {
		this.status = status;
	}

	public void setStatus(String status) {
		this.status = EnumContentHolder.valueOf(status, TaskStatus.class);
	}

	public String getStart_date() {
		return start_date;
	}

	public void setStart_date(String start_date) {
		this.start_date = start_date;
	}

	public String getDue_date() {
		return due_date;
	}

	public void setDue_date(String due_date) {
		this.due_date = due_date;
	}

	public TaskPriority getPriority() {
		return priority;
	}

	public void setPriority(TaskPriority priority) {
		this.priority = priority;
	}

	public void setPriority(String priority) {
		this.priority = EnumContentHolder.valueOf(priority, TaskPriority.class);
	}

	public String getComplete_progress() {
		return complete_progress;
	}

	public void setComplete_progress(String complete_progress) {
		this.complete_progress = complete_progress;
	}

	public TaskRemider getReminder() {
		return reminder;
	}

	public void setReminder(TaskRemider reminder) {
		this.reminder = reminder;
	}

	public void setReminder(String reminder) {
		this.reminder = EnumContentHolder.valueOf(reminder, TaskRemider.class);
	}

	public User getCreateby() {
		return createby;
	}

	public void setCreateby(User createby) {
		this.createby = createby;
	}

	public User getUpdateby() {
		return updateby;
	}

	public void setUpdateby(User updateby) {
		this.updateby = updateby;
	}

	public User getAssignee() {
		return assignee;
	}

	public void setAssignee(User assignee) {
		this.assignee = assignee;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((task_id == null) ? 0 : task_id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Task other = (Task) obj;
		if (task_id == null) {
			if (other.task_id != null)
				return false;
		} else if (!task_id.equals(other.task_id))
			return false;
		return true;
	}

	public String toFormatString() {
		return "Task [task_id=" + task_id + ", subject=" + subject + ", type=" + type + ", description=" + description
				+ ", createby=" + createby + ", updateby=" + updateby + ", create_date=" + create_date
				+ ", update_date=" + update_date + ", status=" + status + ", assignee=" + assignee + ", start_date="
				+ start_date + ", due_date=" + due_date + ", priority=" + priority + ", complete_progress="
				+ complete_progress + ", reminder=" + reminder + "]";
	}

}
